/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PIPELINE_START_H
#define PIPELINE_START_H

#include <ace/xcomponent/native_interface_xcomponent.h>
#include <functional>
#include <list>
#include <uv.h>

#include "base/utils/macros.h"

class XComponentContainer {
public:
    XComponentContainer(OH_NativeXComponent* n, void* w=nullptr) : nativeXComponent_(n), window_(w), width_(0), height_(0), created_(false), createNodes_(nullptr) {}

    OH_NativeXComponent* GetNativeXComponent() { return nativeXComponent_; }
    void* GetWindow() { return window_; }
    uint64_t GetWidth() { return width_; }
    uint64_t GetHeight() { return height_; }
    bool GetCreated() { return created_; }
    const std::function<void()>& GetCreateNodes() { return createNodes_; }

private:
    OH_NativeXComponent* nativeXComponent_;
    void* window_;
    uint64_t width_;
    uint64_t height_;
    bool created_;
    std::function<void()> createNodes_;
    static std::list<XComponentContainer> xComponentList_;

public:
    static std::list<XComponentContainer>& XComponentList() { return xComponentList_;}
    static OH_NativeXComponent* GetLatestNativeXComponent();
    static void OnInit(OH_NativeXComponent* x) ;
    static bool OnPrePipelineStarted(OH_NativeXComponent* x, void* w, uint64_t width, uint64_t height, const std::function<void()> &fun);
    static void OnSurfaceDestroyed(OH_NativeXComponent* x, void* w);
};
#endif // PIPELINE_START_H